﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using QDT.Core.Members;
using QDT.Core.Projects;

namespace QDT.Core.Deals
{
    /// <summary>
    /// 投标失败异常类
    /// </summary>
    public class BidException:Exception,ISerializable
    {
         public BidException():base()
        {
            StatusCode = BidException.Unknow;
        }

        public BidException(string message):base(message)
        {
            StatusCode = BidException.Unknow;
        }

        public BidException(string message, Exception inner):base(message,inner)
        {
            StatusCode = BidException.Unknow;
        }

        public BidException(int statusCode,User user,Project project) {
            
            StatusCode = statusCode;
            
            User = user;
            
            Project = project;
        }

        public BidException(int statusCode):this(statusCode,null,null)
        {
        }

        public User User { get; set; }

        public Project Project { get; set; }

        public int StatusCode { get; set; }

        /// <summary>
        /// 未知的异常
        /// </summary>
        public const int Unknow = 0;

        /// <summary>
        /// 无效的项目状态
        /// </summary>
        public const int InVaildProjectStatus = 1;

        /// <summary>
        /// 超出项目可投余额
        /// </summary>
        public const int ProjectNeedOutOfRange = 2;

        /// <summary>
        /// 用户余额不足
        /// </summary>
        public const int UserLackOfBalance = 3;

        /// <summary>
        /// 小于最小可投金额的范围
        /// </summary>
        public const int MinLoanOutOfRange= 4;

        /// <summary>
        /// 超出最大可投金额的范围
        /// </summary>
        public const int MaxLoanOutOfRange = 5;

        /// <summary>
        /// 无效的投资人
        /// </summary>
        public const int InvaildLender = 6;

        /// <summary>
        /// 投资金额不能是负数和零
        /// </summary>
        public const int NotNegativeOrZero = 7;


        public override string Message
        {
            get
            {
                switch (StatusCode)
                {
                    case InVaildProjectStatus:
                        return "无效的项目状态.";
                    case ProjectNeedOutOfRange:
                        return "超出项目可投余额";
                    case UserLackOfBalance:
                        return "用户余额不足";
                    case MinLoanOutOfRange:
                        return "小于最小可投金额";
                    case MaxLoanOutOfRange:
                        return "超出最大可投金额";
                    case InvaildLender:
                        return "无效的投资人";
                    case NotNegativeOrZero:
                        return "投资金额不能是负数和零";
                    default:
                        return base.Message;
                }
            }
        }
    }
}
